/*
 * @Author: wriliant 
 * @Date: 2019-06-28 10:03:15
 * @Description: 项目所需的一些公共方法
 * @Last Modified by: wriliant
 * @Last Modified time: 2019-06-28 10:03:15
 */


/**
 * 将结果返回
 * @param int code 状态码(code:0 返回正常结果，code :700x系列 用户模块错误)
 * @param String message 提示信息
 * @param Object resultValue 结果集
 * @param {*} res 
 */
const returnMsg = (code,message,resultValue,res)=>{
    const result = {
        code:code,
        message:message,
        resultValue
    }
    res.json(result);
}

/**
 * 生成唯一用户id
 */
const getUniqueId = ()=>{
    return (S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4()); 
}
function S4() { 
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1); 
 }; 

/**
 * 获取当前时间
 */
 const getNowFormatDate = ()=> {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
	var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
	var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
			+ " "  + date.getHours()  + seperator2  + date.getMinutes()
			+ seperator2 + date.getSeconds();
	return currentdate;
}

module.exports = {
    returnMsg,
    getUniqueId,
    getNowFormatDate
}